package com.academic_system.service.impl;

import com.academic_system.mapper.CourseDao;
import com.academic_system.model.Course;
import com.academic_system.service.CourseService;
import com.academic_system.util.Message;
import com.academic_system.util.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 20155878 鄢前州
 * @Description 课程管理
 * @create 22:09 2018/4/27
 **/
@Service
public class CourseImpl implements CourseService {
    @Autowired
    @Resource
    private CourseDao courseDao;
    /**
     * @param
     * @Description 不重复课程类型
     * @author 20155884 王晓阳
     * @methodName
     * @returnType
     **/
    @Override
    public Message queryAllCouseDistict() {
        List<Course> list = new ArrayList<Course>();
        list = courseDao.queryAllCouseDistict();
        System.out.println("-courseimpl-queryAllCouseDistict-" + list.size());
        for (Course c : list) {
            System.out.println("-courseimpl-queryAllCouseDistict-type-" + c.getCourseType());
        }
        if (list.size() != 0) {
            return Message.success().add("1", list);
        }
        return Message.fail();
    }

    /**
     * @param
     * @Description 不重复通过课程课程类型查找课程名称
     * @author 20155884 王晓阳
     * @methodName
     * @returnType
     **/
    @Override
    public Message queryCousecourseType(Course course) {
        List<Course> courseList = new ArrayList<Course>();
        courseList = courseDao.queryCousecourseType(course);
        System.out.println("-courseimpl-queryCousecourseType-" + courseList.size());
        for (Course c : courseList) {
            System.out.println("-courseimpl-queryCousecourseType-type-" + c.getCourseType());
        }
        if (courseList.size() != 0) {
            return Message.success().add("courseList", courseList);
        }
        return Message.fail();
    }

    /**
     * @param
     * @Description 通过课程名称课程类型查找课程id
     * @author 20155884 王晓阳
     * @methodName
     * @returnType
     **/
    @Override
    public Msg queryCouseId(String courseType, String courseName){
        Course course = courseDao.queryCouseId(courseType,courseName);
        System.out.println("-courseimpl-queryCouseBycourseTypeAndCourseName-" + course.getCourseId());
        if (course!= null) {
            return Msg.addData(100,"course", course);
        }
        return Msg.fail();
    }
}
